/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jogodavelhagui;

/**
 *
 * @author Felipe
 */
public class Campo {
    
    private int campo[][] = new int [3][3];
    
    public Campo() {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                campo[i][j] = 0;
            }
        }
    }
    
    public void alteraCampo(int num, int jogador) {
        int i = num/10;
        int j = num%10;
        if (campo[i][j] == 0) campo[i][j] = jogador;
    }
    
    public int getCampoValor(int num) {
        int i = num/10;
        int j = num%10;
        return campo[i][j];
    }
    
    public int getLinhaValor(int i) {
        return campo[i][0] + campo[i][1] + campo[i][2];
    }
    
    public int getColunaValor(int j) {
        return campo[0][j] + campo[1][j] + campo[2][j];
    }
    
    public int getDiagonal1Valor() {
        return campo[0][0] + campo[1][1] + campo[2][2];
    }
    
    public int getDiagonal2Valor() {
        return campo[0][2] + campo[1][1] + campo[2][0];
    }
    
    public boolean getVictorious() {
        for(int cont = 0; cont < 3; cont++) {
            if (getColunaValor(cont) == -3 || getLinhaValor(cont) == -3 || getDiagonal1Valor() == -3 || getDiagonal2Valor() == -3)
                return true;
            if (getColunaValor(cont) == 3 || getLinhaValor(cont) == 3 || getDiagonal1Valor() == 3 || getDiagonal2Valor() == 3)
                return true;
        }
        return false;
    }
    
    public boolean campoCheio() {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (campo[i][j] == 0) return false;
            }
        }
        return true;
    }
}
